<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <base href="/">
    <link rel="stylesheet" href="../static/layui/css/layui.css">
    <script src="../static/js/jquery-3.2.1.min.js"></script>
    <script src="../static/layui/layui.js"></script>
    <script>
        $(function () {
            $("#btnClose").on("click",function () {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            });

            // 填充管理员信息
            $.get({
                url: 'admin/info/get',
                success: function (result) {
                    if (result && result.success) {
                        var data = result.data.data;
                        $("input[name='username']").val(data.username);
                        $("input[name='email']").val(data.email);
                        $("input[name='phone']").val(data.phone);
                    }else {
                        layer.msg(result.message + "获取管理员信息失败");
                    }
                }
            });

            $("#save").on("click",function () {
                var data = $("form").serialize();
                $.post({
                    url: 'admin/info/update',
                    data: data,
                    success: function (result) {
                        if (result && result.success){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        }else {
                            layer.msg(result.message);
                        }
                    }
                })
            });
        })
    </script>
</head>
<body>
    <div>
        <form class="layui-form model-form">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input name="username" placeholder="请输入用户名" type="text" class="layui-input" maxlength="20"
                           lay-verify="required" required/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input name="email" placeholder="请输入邮箱" type="text" class="layui-input" maxlength="50"
                           lay-verify="email" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机</label>
                <div class="layui-input-block">
                    <input name="phone" placeholder="请输入手机号" type="text" class="layui-input" maxlength="20"
                           lay-verify="phone" />
                </div>
            </div>
            <div class="layui-form-item model-form-footer" align="center">
                <!--<label class="layui-form-label"/></label>-->
                <button id="btnClose" class="layui-btn layui-btn-primary close" type="button">取消</button>
                <button class="layui-btn" lay-filter="userinfo-submit" lay-submit type="button" id="save">保存</button>
            </div>
        </form>
    </div>
</body>
</html>